<template>
    <div style="position: fixed;width: 100%;height: 100%;display: flex;justify-content: center;align-items: center;">
        <Loading size="24px" vertical>获取授权中...</Loading>
    </div>
</template>

<script>
    import {Loading} from 'vant';
    import {getAuthUrl} from '@/api/auth'

    export default {
        name: "Auth2",
        components: {
            Loading
        },
        data() {
            return {}
        },
        mounted() {
            let token = sessionStorage.getItem('access-token')
            if (token) {
                this.$router.replace('/landing')
            } else {
                getAuthUrl().then(res => {
                    if (res.successful) {
                        window.history.replaceState(null, null, '/frontend/landing')
                        window.location.replace(res.data)
                    } else {
                        alert(res.message)
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>